package com.qing.library_manager.controller.readers;

import com.qing.library_manager.domain.dto.ReadersDTO;
import com.qing.library_manager.domain.query.ReadersQuery;
import com.qing.library_manager.service.manager.readers.readersService;
import com.qing.library_manager.common.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/readers")
@Api(tags = {"读者模块"})
public class readersController {

    private final readersService readersService;

    public readersController(com.qing.library_manager.service.manager.readers.readersService readersService) {
        this.readersService = readersService;
    }

    /**
     *  新增读者
     * @param readersDTO
     * @return
     */
    @ApiOperation("新增读者")
    @PostMapping("/addReaders")
    public ResponseResult increaseReaders(@RequestBody ReadersDTO readersDTO) {
        return readersService.increaseReaders(readersDTO);
    }

    /**
     *  新增读者信息
     * @param readersDTO
     * @return
     */
    @ApiOperation("更新读者信息")
    @PostMapping("/updateReaders")
    public ResponseResult updateReaders(@RequestBody ReadersDTO readersDTO) {
        return readersService.updateReadersByName(readersDTO);
    }

    /**
     *  删除读者信息
     * @param readersShowId
     * @return
     */
    @ApiOperation("删除读者信息")
    @GetMapping("/deleteReaders/{readersShowId}")
    public ResponseResult deleteReaders(@PathVariable int readersShowId) {
        return readersService.deleteReadersByName(readersShowId);
    }

    /**
     *  分页查询读者信息
     * @param
     * @return
     */
    @ApiOperation("分页查询读者信息")
    @PostMapping("/queryReaders/{pageNum}/{pageSize}")
    public ResponseResult queryReaders(@PathVariable int pageNum,
                                       @PathVariable int pageSize,
                                       @RequestBody ReadersQuery readersQuery
                                       ) {
        return readersService.queryAllReadersInit(pageNum,pageSize,readersQuery);
    }

    /**
     *  根据id查询用户信息
     * @param
     * @return
     */
    @ApiOperation("根据id查询用户信息")
    @GetMapping("/queryReadersById/{readersShowId}")
    public ResponseResult queryReadersById(@PathVariable int readersShowId) {
        return readersService.queryReadersById(readersShowId);
    }

    /**
     *  获取全部读者数据
     * @param
     * @return
     */
    @ApiOperation("获取全部读者数据")
    @GetMapping("/queryAllReaders")
    public ResponseResult queryAllReaders() {
        return readersService.queryAllReaders();
    }

}
